﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NetworkPower.DXF.Exchange
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (txtOriginal.Text.Trim().Length == 0 || txtDestination.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入完整字符.");
                return;
            }
            //var path = System.Reflection.Assembly.GetExecutingAssembly().Location;
            try
            {
                var path = AppDomain.CurrentDomain.BaseDirectory + @"Data\220\220";
                string[] files = Directory.GetFiles(path);

                var txtOri = txtOriginal.Text;
                var txtDes = txtDestination.Text;


                foreach (string file in files)
                {
                    string fileName = System.IO.Path.GetFileName(file);
                    if (System.IO.Path.GetExtension(fileName).Equals(".dxf"))
                    {
                        //string text = File.ReadAllText(@"D:\1.dxf");
                        //System.IO.Path.GetFullPath
                        var fullpath = path + @"\" + fileName;
                        string text = File.ReadAllText(fullpath);
                        text = text.Replace(txtOriginal.Text, txtDestination.Text);
                        File.WriteAllText(fullpath, text);
                    }

                }
                MessageBox.Show("替换成功.");
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
